﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication4
{
    public partial class WebForm3 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string name = TextBox1.Text;
            string pwd = TextBox2.Text;
            string age = RadioButton2.Checked ? "1" : "0";
            string email = TextBox4.Text;

            string url = "server=.;uid=sa;pwd=123456;database=Student";
            SqlConnection con = new SqlConnection(url);

            string sql = "insert into StudentInfo (name,age,email,pwd) values (@name,@age,@email,@pwd)";
            SqlParameter[] pars =
            {
                new SqlParameter("@name",name),
                new SqlParameter("@pwd",pwd),
                new SqlParameter("@age",age),
                new SqlParameter("@email",email)
            };

            try
            {
                con.Open();
                SqlCommand com = new SqlCommand(sql,con);
                com.Parameters.AddRange(pars);

                int result = com.ExecuteNonQuery();

                if (result != -1)
                {
                    Label1.Text = "注册成功，<a href='WebForm1.aspx'>去登录</a>";
                }
                else
                {
                    
                    Label1.Text = "注册失败!";
                }

            }
            catch (Exception ex)
            {

                throw new Exception(ex.Message);
            }
            finally
            {
                if (con != null)
                {
                    con.Close();
                }
            }

        }
    }
}